package bookManage;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 归还记录
 * 
 * @author 伟❤志
 *
 */
public class RebackModel {
	private int cardId;// 借阅卡id
	private int bookId;// 图书id
	private String bookName;// 图书名
	private Date date;// 归还时间
	
	public String getBookName() {
		return bookName;
	}

	public void setBookName(String bookName) {
		this.bookName = bookName;
	}

	public String getDate() {
		SimpleDateFormat sdf = new SimpleDateFormat();
		sdf.applyPattern("yyyy-MM-dd HH:mm:ss");// 格式化时间
		return sdf.format(date);
	}

	public void setDate() {
		Date date = new Date();
		this.date = date;
	}

	public int getCardId() {
		return cardId;
	}

	public void setCardId() {
		int cardId = Card.userId;
		this.cardId = cardId;
	}

	public int getBookId() {
		return bookId;
	}

	public void setBookId(int bookId) {
		this.bookId = bookId;
	}

	/**
	 * 查询全部还书记录
	 */
	public void selectAll() {
		for (RebackModel rebackModel:BookTest.rebacks) {
			rebackInfo(rebackModel);

		}
	}

	/**
	 * 查询个人归还记录
	 */
	public void selectByUser() {
		for (RebackModel rebackModel:BookTest.rebacks) {
			if (rebackModel.getCardId() == Card.userId) {// 当前登录用户的借阅卡id
				rebackInfo(rebackModel);
			}
		}
	}

	/**
	 * 查询图书归还记录
	 */
	public void selectByBook(String bookName) {
		
		for (RebackModel rebackModel:BookTest.rebacks) {
			if (rebackModel.getBookName().equals(bookName)) {
				rebackInfo(rebackModel);
			}
		}
	}

	/**
	 * 归还记录详情
	 * 
	 * @param borrowModel
	 */
	public void rebackInfo(RebackModel rebackModel) {

		System.out.println("=================");
		System.out.println("借阅卡id：" + rebackModel.getCardId());
		System.out.println("图书编号：" + rebackModel.getBookId());
		System.out.println("图书名：" + rebackModel.getBookName());
		System.out.println("还书时间：" + rebackModel.getDate());
		System.out.println("=================");
	}

	/**
	 * 增加归还记录
	 * 
	 * @param cardId
	 * @param bookId
	 */
	public void addReback(int cardId) {
		RebackModel rebackModel = new RebackModel();

		BookModel bookModel = new BookModel();
		BookModel book = bookModel.selectById(bookId);// 根据图书id得到图书相关信息

		rebackModel.setBookId(bookId);
		rebackModel.setCardId();
		rebackModel.setBookName(book.getName());
		rebackModel.setDate();

		BookTest.rebacks.add(rebackModel);
	}
}
